]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ci: Check snippets in coding style
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 25 Jan 2024 23:56:35 +0000 (00:56 +0100)
committerMarge Bot <marge-bot@gnome.org>
Sat, 27 Jan 2024 18:18:23 +0000 (18:18 +0000)
To avoid having the coding style get out of sync with the actual
coding style in the future, run eslint on the individual snippets
when either the guide or the linter config change.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3146>

.gitlab-ci.yml
.gitlab-ci/eslint-coding-style.sh [new file with mode: 0755]

index 8dadcf6aafed90951bec58873832c1f75a9120dc..8d881ba7fc2723f0a5f2766030525c394172e8b6 100644 (file)
@@ -149,6 +149,21 @@ eslint:
       junit: ${LINT_LOG}
     when: always
 
+eslint-doc:
+  extends:
+    - .fdo.distribution-image@fedora
+    - .gnome-shell.fedora
+  stage: review
+  script:
+    - export NODE_PATH=$(npm root -g)
+    - ./.gitlab-ci/eslint-coding-style.sh
+  rules:
+    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
+      changes:
+        - HACKING.md
+        - .eslintrc.yml
+        - lint/*
+
 potfile_c_check:
   extends:
     - .fdo.distribution-image@fedora
diff --git a/.gitlab-ci/eslint-coding-style.sh b/.gitlab-ci/eslint-coding-style.sh
new file mode 100755 (executable)
index 0000000..783075b
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+SRCDIR=$(realpath $(dirname $0)/..)
+OUTDIR=$(mktemp --directory --tmpdir=$SRCDIR)
+trap "rm -rf $OUTDIR" EXIT
+
+# Turn ```javascript``` code snippets in the
+# style guide into .js files in $OUTDIR
+awk --assign dir=$OUTDIR -- '
+  BEGIN {
+    do_print = 0;
+    cur = 0;
+  }
+
+  # end of code snippet
+  /```$/ {
+    do_print = 0;
+    cur++;
+  }
+
+  do_print {
+    # remove one level of indent
+    sub("    ","")
+
+    # the following are class snippets, turn them
+    # into functions to not confuse eslint
+    sub("moveActor","function moveActor")
+    sub("desaturateActor","function desaturateActor")
+
+    # finally, append to the currently generated .js file
+    print >> dir "/" cur ".js";
+  }
+
+  # start of code snippet
+  /```javascript$/ {
+    do_print = 1;
+  }
+' HACKING.md
+
+eslint \
+  --rule 'no-undef: off' \
+  --rule 'no-unused-vars: off' \
+  --rule 'no-invalid-this: off' $OUTDIR/*.js